﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace Windows8Accelerator.Core.Xaml.ViewModels
{
    public class CurrentVisualStateChangedEventArgs : EventArgs {
        public string VisualState { get; set; }
    }

    public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
        {
            if (object.Equals(storage, value)) return false;

            storage = value;
            this.OnPropertyChanged(propertyName);
            return true;
        }

        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var eventHandler = this.PropertyChanged;
            if (eventHandler != null)
            {
                eventHandler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private string _CurrentVisualState;
        public string CurrentVisualState
        {
            get { return this._CurrentVisualState; }
            set 
            {
                if (this.SetProperty(ref this._CurrentVisualState, value))
                {
                    OnCurrentVisualStateChanged(value);
                }                
            }
        }

        protected void OnCurrentVisualStateChanged(string visualState)
        {
            if (CurrentVisualStateChanged != null)
                CurrentVisualStateChanged(this, new CurrentVisualStateChangedEventArgs() { VisualState = visualState });
        }

        public event EventHandler<CurrentVisualStateChangedEventArgs> CurrentVisualStateChanged;
    }
}
